package 链表;

/**
 * https://leetcode-cn.com/problems/linked-list-cycle/
 * 利用 快慢指针
 * @author Mxb
 * @version 1.0
 * @date 2020/2/23 22:36
 */
public class _141_环形链表 {
    public boolean hasCycle(ListNode head) {
        // 如果链表为空，返回false
        if(head ==null || head.next==null) return false;

        // 慢节点
        ListNode solw = head;
        // 快节点
        ListNode fast = head.next;

        while (fast != null && fast.next != null){
            if(solw == fast) return true;
            solw = solw.next;
            fast = fast.next.next;
        }
        return false;
    }
}
